Skip to content

feat(python): use pyrefly and ruff to replace pylsp#1489

Closed
Cloud0310 wants to merge 6 commits intoayamir:mainfrom
Cloud0310:0.11
Closed

feat(python): use pyrefly and ruff to replace pylsp#1489
Cloud0310 wants to merge 6 commits intoayamir:mainfrom
Cloud0310:0.11

Conversation

@Cloud0310
Copy link
Copy Markdown
Contributor

Using pyrelfy to replace the default pylsp as the lsp, using ruff as the linter and formatter.

@charliie-dev
Copy link
Copy Markdown
Collaborator

charliie-dev commented Jul 29, 2025

i'm wondering why pyrefly instead of ty.
fyi. ty and ruff are from the same company, i guess they will work better together?

some articles i read earlier this year:
https://blog.edward-li.com/tech/comparing-pyrefly-vs-ty/
https://www.infoworld.com/article/4005961/pyrefly-and-ty-two-new-rust-powered-python-type-checking-tools-compared.html

also, tbh, i think it's too early to introduce pyrefly nor ty to this widely-used nvimdots since their both in their early stage.

@ayamir
Copy link
Copy Markdown
Owner

ayamir commented Jul 30, 2025

Make all of them as configurable options seems a better choice?

@charliie-dev
Copy link
Copy Markdown
Collaborator

tbh, i think we can close this PR now and wait 'til they got more mature

@Cloud0310
Copy link
Copy Markdown
Contributor Author

Make all of them as configurable options seems a better choice?

Doing a refactor for this now, later I will PR again.

Copy link
Copy Markdown
Collaborator

@charliie-dev charliie-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Cloud0310
Copy link
Copy Markdown
Contributor Author

sry for the little bugs here, please review again. 🤕

@Cloud0310
Copy link
Copy Markdown
Contributor Author

Also, I'm thinking about whether the LSP config should be aligned with original pylsp config.
In the last commit, the config is just the default config with all three plugins pyrefly, ty and ruff.

@ayamir ayamir changed the base branch from 0.11 to main August 3, 2025 06:33
@ayamir ayamir changed the base branch from main to 0.11 August 3, 2025 12:52
@Jint-lzxy Jint-lzxy changed the base branch from 0.11 to main August 3, 2025 13:19
@misumisumi
Copy link
Copy Markdown
Collaborator

misumisumi commented Aug 15, 2025

Sorry I'm so busy that I haven't been able to participate much.

Personally, I don't know if I need to change it from pylsp (I've never used pyrefly but...).
Do we need to switch from pylsp+ruff quickly?

am concerned that if exceptional handling is permitted in a particular language, it will lead to the possibility that the introduction of unstable LSPs will also be permitted in other languages in the future.
I think this could lead to bloating of the code.
Therefore, rather than merging exception handling, it is better to have the user verify with override and then create PR again when it matures.

For now, I would like to make a proposal to put it on hold for discussions, projects, etc.

@Cloud0310
Copy link
Copy Markdown
Contributor Author

Sorry I'm so busy that I haven't been able to participate much.

Personally, I don't know if I need to change it from pylsp (I've never used pyrefly but...). Do we need to switch from pylsp+ruff quickly?

am concerned that if exceptional handling is permitted in a particular language, it will lead to the possibility that the introduction of unstable LSPs will also be permitted in other languages in the future. I think this could lead to bloating of the code. Therefore, rather than merging exception handling, it is better to have the user verify with override and then create PR again when it matures.

For now, I would like to make a proposal to put it on hold for discussions, projects, etc.

I also agree with the idea of making it a proposal. Happy to help with this, anything I can do further?

@ayamir ayamir marked this pull request as draft August 18, 2025 06:58
@Cloud0310
Copy link
Copy Markdown
Contributor Author

I would like to open the pr again when its more suitable to swtich to new python lsp, closing this now.

@Cloud0310 Cloud0310 closed this Aug 22, 2025
@Cloud0310
Copy link
Copy Markdown
Contributor Author

i'm wondering why pyrefly instead of ty. fyi. ty and ruff are from the same company, i guess they will work better together?

some articles i read earlier this year: https://blog.edward-li.com/tech/comparing-pyrefly-vs-ty/ https://www.infoworld.com/article/4005961/pyrefly-and-ty-two-new-rust-powered-python-type-checking-tools-compared.html

also, tbh, i think it's too early to introduce pyrefly nor ty to this widely-used nvimdots since their both in their early stage.

Recently, I tried both of them. I guess now the pyrefly is more implemented then ty, base on my own basic using experience. The pyrefly would correctly imply type from basic python std lib most of the time. On the contrary, ty contains loads of list[@todo] things.
What's more is that by their claim on its official website that its been tested with Meta's own codebase at scale. I guess maybe its time for us to reopen the PR again?

@charliie-dev
Copy link
Copy Markdown
Collaborator

charliie-dev commented Oct 9, 2025

What's more is that by their claim on its official website that its been tested with Meta's own codebase at scale. I guess maybe its time for us to reopen the PR again?

looking cool! there's also a new blog of the pyrefly devs tested on numpy. sounds solid for me!

but i have some suggestions for the pr:

  1. since now pyrefly is not that "experimental" for python, i think we can remove the extra settings in lua/core/settings.lua and just add in "lsp_deps".
  2. keep lua/modules/configs/completion/mason-lspconfig.lua as usual and config ruff in lua/modules/configs/completion/null-ls.lua for none-ls is our only way to config linters and formatters.
  3. clean up extra config for pylsp like in here.

@Cloud0310
Copy link
Copy Markdown
Contributor Author

Cloud0310 commented Oct 9, 2025

What's more is that by their claim on its official website that its been tested with Meta's own codebase at scale. I guess maybe its time for us to reopen the PR again?

looking cool! there's also a new blog of the pyrefly devs tested on numpy. sounds solid for me!

but i have some suggestions for the pr:

1. since now `pyrefly` is not that "experimental" for python, i think we can remove the extra settings in `lua/core/settings.lua` and just add in "lsp_deps".

2. keep `lua/modules/configs/completion/mason-lspconfig.lua` as usual and config `ruff` in `lua/modules/configs/completion/null-ls.lua` for `none-ls` is our only way to config linters and formatters.

3. clean up extra config for `pylsp` like in [here](https://github.com/ayamir/nvimdots/blob/367008a5a4be1998b0b7d29524a4e750dc022d99/lua/modules/configs/completion/mason-lspconfig.lua#L128-L178).

I will try to reopen and PR again, thanks for the suggestions. It's been my first time to contribute to a neovim project, if there's problems just let me know.

@Cloud0310
Copy link
Copy Markdown
Contributor Author

Cloud0310 commented Oct 9, 2025

@CharlesChiuGit After a little bit of research, now none-ls regards ruff as a LSP instead of a formatter.

Hence, we have two options:

  1. Add none-ls-extra as a source of formatter and linter
  2. As the repo mentioned and now ruff also regards itself as a LSP, we install is via mason

Guess the second options is more reasonable for me, I would like your idea on this.

@charliie-dev
Copy link
Copy Markdown
Collaborator

Hence, we have two options:

  1. Add none-ls-extra as a source of formatter and linter
  2. As the repo mentioned and now ruff also regards itself as a LSP, we install is via mason

Guess the second options is more reasonable for me, I would like your idea on this.

cool, sounds gd to me. but since we block server formatting capabilities by default, don't forget to add ruff to settings["server_formatting_block_list"] in settings.lua and set it to false.

u can check why we block server formatting by default in https://github.com/ayamir/nvimdots/wiki/Knowledge-Garden#-lsp-related-issues.

@Cloud0310
Copy link
Copy Markdown
Contributor Author

Cloud0310 commented Oct 9, 2025

@CharlesChiuGit Thanks for your help, fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants